/**
 @file ctc_cli.h

 @date 2010-7-9

 @version v2.0

  The file defines Macro, stored data structure for ctc cli
*/
#ifndef _CTC_CLI_H
#define _CTC_CLI_H

#ifdef __cplusplus
extern "C" {
#endif

#include "sal.h"
#include "sal_types.h"

#include "ctc_vti.h"
#include "ctc_cmd.h"
#include "ctc_regex.h"
#include "ctc_common_cli.h"

/* CLI modes.  */

#define EXEC_MODE 0
#define CTC_SDK_MODE 1
#define CTC_CMODEL_MODE 2
#define CTC_SDK_OAM_CHAN_MODE 3
#define CTC_DEBUG_MODE 4
#define CTC_DBG_TOOL_MODE 5
#define CTC_CTCCLI_MODE 6
#define CTC_INTERNAL_MODE 7
#define CTC_APP_MODE 8
#define CTC_DKITS_MODE 9
#define CTC_STRESS_MODE 10
#define CTC_PTP_MODE 11
#define CTC_ASW_MODE 12
#define CTC_CLI_MODE_MAX 13

/* Return value.  */
#define CLI_SUCCESS           0
#define CLI_ERROR             1
#define CLI_AUTH_REQUIRED     2
#define CLI_EOL               3

/* Max length of each token.  */
#define MAX_TOKEN_LENGTH   256

/* Used for shield system API other than show command */
#undef SDK_INTERNAL_CLIS

/* Used for shield system API in show command */
#define SDK_INTERNAL_CLI_SHOW

/* Common descriptions. */
#define CTC_CLI_SHOW_STR "Show running system information"
#define CTC_CLI_NO_STR      "Negate a command or set its defaults"
#define CTC_CLI_CLEAR_STR   "Clear functions"
#define CTC_CLI_ENABLE      "Enable functions"
#define CTC_CLI_DISABLE     "Disable functions"
#define CTC_CLI_SHOW_SYS_MEM_STR  "Memory information"
#define CTC_CLI_DEBUG_STR  "Debugging functions"
#define CTC_CLI_BOOL_VAR_STR  "Boolean variable"


/* Multicast static route CLI strings */
#define CTC_CLI_GET_ARGC_INDEX_ENHANCE(str) ctc_cli_get_prefix_item(&argv[0], argc, str, 0)
#define CTC_CLI_GET_ARGC_INDEX(str) CTC_CLI_GET_ARGC_INDEX_ENHANCE(str)

#define CTC_CLI_GET_SPECIFIC_INDEX(str, idx) ctc_cli_get_prefix_item(&argv[idx], (argc - (idx)), str, sal_strlen(str))
#define CTC_CLI_GET_SPECIFIC_INDEX_ENHANCE(str, idx) ctc_cli_get_prefix_item(&argv[idx], (argc - (idx)), str, 0)
#define CTC_CLI_GET_RANGE_INDEX(str, start_idx, end_idx) ctc_cli_get_prefix_item(&argv[start_idx], (end_idx - start_idx), str, sal_strlen(str))
#define CLI_CLI_STR_EQUAL(str, idx)  (0 == sal_strncmp((str), argv[(idx)], sal_strlen(str)))
#define CTC_CLI_STR_EQUAL_ENHANCE(str, idx)  \
    ((0 == sal_strncmp((str), argv[(idx)], sal_strlen(str))) && (sal_strlen(argv[idx]) == sal_strlen(str)))
#define INDEX_VALID(index)  (0xFF != (index))

#define CTC_CLI_STR_IS_ARRAY_START(STR)     (STR && STR[0] == '[')

#define CTC_CLI_STR_ARRAY_NUM(STR) ctc_cli_get_array_num(STR)

#define CLI_MROUTE_STR      "Configure static multicast routes"

#define UINT64_STR_LEN      21

#define CTC_MAX_UINT16_VALUE 0xFFFF
#define CTC_MAX_UINT32_VALUE 0xFFFFFFFF
#define CTC_MAX_UINT8_VALUE 0xFF

#define MAX_FILE_NAME_SIZE      256

#define MAX_CLI_STRING_LEN 1000

#define CTC_MAX_ARRAY_LEN(array)      (sizeof(array) - 1)  /**< calculate array size */

struct ctc_l2_write_info_para_s
{
    char file[MAX_FILE_NAME_SIZE];
    void* pdata;
    ctc_vti_t* vty;
};
typedef struct ctc_l2_write_info_para_s ctc_l2_write_info_para_t;
struct ctc_cli_ipuc_traverse_data_s
{
    ctc_vti_t* vty;
};
typedef struct ctc_cli_ipuc_traverse_data_s ctc_cli_ipuc_traverse_data_t;
typedef int (* CTC_CLI_OUT_FUNC) (const char* str, ...);

int ctc_cli_out_ext(ctc_vti_t *vty, const char* fmt, ...);
int ctc_cli_out_basic(const char* fmt, ...);

#ifdef HAVE_ISO_MACRO_VARARGS
#define CTC_CLI(func_name, cli_name, cmd_str, ...)  \
    char* cli_name ## _help[] = {__VA_ARGS__, NULL}; \
    char* cli_name ## _debug[] = {#cli_name,NULL}; \
    DEFUN(func_name, cli_name, cmd_str, cli_name ## _help,cli_name ## _debug)
#else
#define CTC_CLI(func_name, cli_name, cmd_str, ARGS...) \
    char* cli_name ## _help[] = {ARGS, NULL}; \
    char* cli_name ## _debug[] = {#cli_name,NULL}; \
    DEFUN(func_name, cli_name, cmd_str, cli_name ## _help, cli_name ## _debug)
#endif

extern uint32
ctc_cmd_get_value(int32* ret, char* name, char* str, uint32 min, uint32 max, uint8 type);
extern int32
ctc_cmd_get_timestamp(char* name, char* str, struct tm* p_user_ts);
extern int32
ctc_cmd_str2int(char* str, int32* ret);
extern uint32
ctc_cmd_str2uint(char* str, int32* ret);
extern uint64
ctc_cmd_str2uint64(char* str, int32* ret);
extern void
    ctc_uint64_to_str(uint64 src, char dest[UINT64_STR_LEN]);
extern int32
ctc_cmd_str2nint (char *str, int32 *ret, uint32 *val);
extern int32
ctc_cmd_xstr2array (char *str, void *array, uint8 arr_len, uint8 arr_type /* 0-uint32, 1-uint16, 2-uint8 */);


extern int32
ctc_cmd_judge_is_num(char* str);

extern char*
ctc_cli_get_debug_desc_ext(ctc_vti_t* vty, unsigned char level);


#define CTC_CLI_CHK_ARGV(argx) \
{\
         if((&argx - &argv[0]) >= argc)\
         {\
            ctc_cli_out("%% Invalid value\n"); \
            return CLI_ERROR;\
         }\
}

#define CTC_CLI_GET_INTEGER(NAME, V, STR)                \
    {                                                  \
        int32 retv;                                      \
        CTC_CLI_CHK_ARGV(STR);                          \
        (V) = ctc_cmd_str2int((STR), &retv);            \
        if (g_cli_parser_param_en)                      \
        {                                               \
            ctc_cli_out("Param %s:%d\n",NAME,V);            \
        }                                                  \
        if (retv < 0)                                    \
        {                                              \
            ctc_cli_out("%% Invalid %s value\n", NAME); \
            return CLI_ERROR;                            \
        }                                              \
    }

#define CTC_CLI_GET_INTEGER_N(NAME,V,STR)                             \
    {                                                                      \
      int32 retv;                                                               \
      int32 val = 0;                                                            \
      CTC_CLI_CHK_ARGV(STR);                          \
      val = ctc_cmd_str2nint ((STR), &retv, V);                              \
      if (g_cli_parser_param_en)                      \
      {                                               \
        ctc_cli_out("Param %s:%d\n",NAME,*(V));            \
      }                                                  \
      if ((retv < 0) || (val < 0))                             \
        {                                                                     \
          ctc_cli_out ("%% Invalid %s value\n", NAME);                       \
          return CLI_ERROR;                                                   \
        }                                                                     \
    }

#define CTC_CLI_GET_INTEGER_RANGE(NAME, V, STR, MIN, MAX)  \
    {                                                  \
        int32 retv;                                      \
        CTC_CLI_CHK_ARGV(STR);                          \
        (V) = ctc_cmd_str2int((STR), &retv);            \
        if (g_cli_parser_param_en)                      \
        {                                               \
            ctc_cli_out("Param %s:%d\n",NAME,V);            \
        }                                                  \
        if (retv < 0 || (V) < (MIN) || (V) > (MAX))      \
        {                                              \
            ctc_cli_out("%% Invalid %s value\n", NAME); \
            return CLI_ERROR;                            \
        }                                              \
    }

#define CTC_CLI_GET_INTEGER64(NAME, V, INT, STR, MIN, MAX)  \
    {                                                  \
        int32 retv;                                      \
        int32 val = 0;                                   \
        CTC_CLI_CHK_ARGV(STR);                          \
        (V) = ctc_cmd_str2int((STR), &retv);            \
        sal_memcpy(&INT.l[0], &val, 4);                 \
        sal_memcpy(&INT.l[1], &(V), 4);                 \
        if (g_cli_parser_param_en)                      \
        {                                               \
            ctc_cli_out("Param %s:%PRId64\n",NAME,V);            \
        }                                                  \
        if (retv < 0 || (V) < (MIN) || (V) > (MAX))      \
        {                                              \
            ctc_cli_out("%% Invalid %s value\n", NAME); \
            return CLI_ERROR;                            \
        }                                              \
    }

#define CTC_CLI_GET_UINT32(NAME, V, STR)                                      \
{                                                                               \
    int32 ret;                                                                  \
    CTC_CLI_CHK_ARGV(STR);                          \
    (V) =  ctc_cmd_get_value(&ret, (NAME), (STR), 0, CTC_MAX_UINT32_VALUE, 2);  \
    if (g_cli_parser_param_en)                      \
    {                                               \
        ctc_cli_out("Param %s:%u\n",NAME,V);            \
    }                                                  \
    if(0 != ret)   \
    {                                                                               \
        return CLI_ERROR;                                                           \
    }                                                                               \
}

#define CTC_CLI_GET_UINT64(NAME, V, STR)                    \
    {                                                       \
        int32 retv;                                         \
        CTC_CLI_CHK_ARGV(STR);                          \
        (V) = ctc_cmd_str2uint64((STR), &retv);             \
         if (g_cli_parser_param_en)                      \
        {                                               \
            ctc_cli_out("Param %s:%"PRIu64"\n",NAME,V);            \
        }                                                  \
        if (retv < 0)                                       \
        {                                                   \
            ctc_cli_out("%% Invalid %s value\n", NAME);     \
            return CLI_ERROR;                               \
        }                                                   \
    }

#define CTC_CLI_GET_UINT8_ARRAY(NAME, ARR, NUM, STR, RET)                    \
    {                                                       \
        CTC_CLI_CHK_ARGV(STR);                          \
        RET = ctc_cmd_get_value_array(NAME, (STR), ARR, NUM, 0);             \
    }

#define CTC_CLI_GET_UINT16_ARRAY(NAME, ARR, NUM, STR, RET)                    \
    {                                                       \
        CTC_CLI_CHK_ARGV(STR);                          \
        RET = ctc_cmd_get_value_array(NAME, (STR), ARR, NUM, 1);             \
    }

#define CTC_CLI_GET_UINT32_ARRAY(NAME, ARR, NUM, STR, RET)                    \
    {                                                       \
        CTC_CLI_CHK_ARGV(STR);                          \
        RET = ctc_cmd_get_value_array(NAME, (STR), ARR, NUM, 2);             \
    }                                                 

#define CTC_CLI_GET_UINT64_ARRAY(NAME, ARR, NUM, STR, RET)                    \
    {                                                       \
        CTC_CLI_CHK_ARGV(STR);                          \
        RET = ctc_cmd_get_value_array(NAME, (STR), ARR, NUM, 3);             \
    }

#define CTC_CLI_GET_UINT32_RANGE(NAME, V, STR, MIN, MAX)                        \
{                                                                               \
    int32 ret;                                                                  \
    CTC_CLI_CHK_ARGV(STR);                          \
    (V) = ctc_cmd_get_value(&ret, (NAME), (STR), (MIN), (MAX), 2);               \
    if (g_cli_parser_param_en)                      \
    {                                               \
        ctc_cli_out("Param %s:%u\n",NAME,V);            \
    }                                                  \
    if(0 != ret)                                                         \
    {                                                                               \
        return CLI_ERROR;                                                           \
    }                                                                               \
}

#define CTC_CLI_GET_UINT16(NAME, V, STR)                                            \
{                                                                               \
    int32 ret;                                                                  \
    CTC_CLI_CHK_ARGV(STR);                          \
    (V) = ctc_cmd_get_value(&ret, (NAME), (STR), 0, CTC_MAX_UINT16_VALUE, 1);   \
    if (g_cli_parser_param_en)                      \
    {                                               \
        ctc_cli_out("Param %s:%u\n",NAME,V);            \
    }                                                  \
    if(0 != ret)   \
    {                                                                               \
        return CLI_ERROR;                                                           \
    }                                                                               \
}

#define CTC_CLI_GET_UINT16_RANGE(NAME, V, STR, MIN, MAX)                            \
{                                                                               \
    int32 ret;                                                                  \
    CTC_CLI_CHK_ARGV(STR);                          \
    (V) = ctc_cmd_get_value(&ret, (NAME), (STR), (MIN), (MAX), 1);              \
    if (g_cli_parser_param_en)                      \
    {                                               \
        ctc_cli_out("Param %s:%u\n",NAME,V);            \
    }                                                  \
    if(0 != ret)   \
    {                                                                               \
        return CLI_ERROR;                                                           \
    }                                                                               \
}

#define CTC_CLI_GET_UINT8(NAME, V, STR)                                              \
{                                                                               \
    int32 ret;                                                                  \
    CTC_CLI_CHK_ARGV(STR);                          \
    (V) = ctc_cmd_get_value(&ret, (NAME), (STR), 0, CTC_MAX_UINT8_VALUE, 0);   \
    if (g_cli_parser_param_en)                      \
    {                                               \
        ctc_cli_out("Param %s:%u\n",NAME,V);            \
    }                                                  \
    if(0 != ret)   \
    {                                                                               \
        return CLI_ERROR;                                                           \
    }                                                                               \
}

#define CTC_CLI_GET_UINT8_RANGE(NAME, V, STR, MIN, MAX)                       \
{                                                                               \
    int32 ret;                                                                  \
    CTC_CLI_CHK_ARGV(STR);                          \
    (V) = ctc_cmd_get_value(&ret, (NAME), (STR), (MIN), (MAX), 0);             \
    if (g_cli_parser_param_en)                      \
    {                                               \
        ctc_cli_out("Param %s:%u\n",NAME,V);            \
    }                                                  \
    if(0 != ret)   \
    {                                                                               \
        return CLI_ERROR;                                                           \
    }                                                                               \
}

#define CTC_CLI_GET_UINT8_NO_MAPPING(NAME, V, STR)           \
    {                                                  \
        int32 retv;                                      \
        uint32 tmp = 0;                                   \
        CTC_CLI_CHK_ARGV(STR);                          \
        tmp = ctc_cmd_str2uint((STR), &retv);           \
        if (g_cli_parser_param_en)                      \
        {                                               \
            ctc_cli_out("Param %s:%s\n",NAME,STR);            \
        }                                                  \
        if (retv < 0 || tmp > CTC_MAX_UINT8_VALUE)       \
        {                                               \
            ctc_cli_out("%% Invalid %s value\n", NAME); \
            return CLI_ERROR;                            \
        }                                               \
        (V) = (uint8)tmp;                                \
    }

#define CTC_CLI_GET_MAC_ADDRESS(NAME, V, STR)                                                                \
    {                                                                                                        \
        int32 retv = 0;                                                                                      \
        uint8 __index = 0;                                                                                   \
        CTC_CLI_CHK_ARGV(STR);                                                                              \
        while (STR[__index] != '\0')                                                                         \
        {                                                                                                    \
            if (STR[__index] == '.'){ retv++; }                                                              \
            __index++;                                                                                       \
        }                                                                                                    \
        if (retv != 2)                                                                                       \
        {                                                                                                    \
            ctc_cli_out("%% invalid %s value\n", NAME);                                                      \
            return CLI_ERROR;                                                                                \
        }                                                                                                    \
        retv = sal_sscanf((STR), "%4hx.%4hx.%4hx", (uint16*)&(V[0]), (uint16*)&(V[2]), (uint16*)&(V[4]));   \
        if (retv != 3)                                                                                       \
        {                                                                                                    \
            ctc_cli_out("%% invalid %s value\n", NAME);                                                      \
            return CLI_ERROR;                                                                                \
        }                                                                                                    \
        *(uint16*)&(V[0]) = sal_htons(*(uint16*)&(V[0]));                                                   \
        *(uint16*)&(V[2]) = sal_htons(*(uint16*)&(V[2]));                                                   \
        *(uint16*)&(V[4]) = sal_htons(*(uint16*)&(V[4]));                                                   \
        if (g_cli_parser_param_en)                                                                            \
        {                                                                                                       \
            ctc_cli_out("Param %s:%.2x%.2x.%.2x%.2x.%.2x%.2x\n",NAME,V[0],V[1],V[2],V[3],V[4],V[5]);                                      \
        }                                                                                                        \
    }

#define CTC_CLI_GET_IPV4_ADDRESS(NAME, V, STR)               \
    {                                                      \
        int32 retv;                                          \
        CTC_CLI_CHK_ARGV(STR);                          \
        retv = sal_inet_pton(AF_INET, (STR), &(V));         \
        if (!retv)                                           \
        {                                                  \
            ctc_cli_out("%% Invalid %s value\n", NAME);     \
            return CLI_ERROR;                                \
        }                                                  \
        (V) = sal_htonl(V);                                  \
        if (g_cli_parser_param_en)                                                                            \
        {                                                                                                       \
            ctc_cli_out("Param %s:%d.%d.%d.%d\n",NAME,(V >> 24 & 0xFF),(V >> 16 & 0xFF),(V >> 8 & 0xFF),(V & 0xFF));  \
        }                                                                                                        \
    }

#define CTC_CLI_GET_IPV6_ADDRESS(NAME, V, STR)           \
    {                                                  \
        int32 retv;                                      \
        CTC_CLI_CHK_ARGV(STR);                          \
        retv = sal_inet_pton(AF_INET6, (STR), &(V));    \
        if (g_cli_parser_param_en)                                                                            \
        {                                                       \
            ctc_cli_out("Param %s:%s\n",NAME,STR);  \
        }                                                   \
        if (!retv)                                       \
        {                                              \
            ctc_cli_out("%% Invalid %s value\n", NAME); \
            return CLI_ERROR;                            \
        }                                              \
    }

#define CTC_CLI_IS_NUM(STR)                           \
    {                                                 \
        int32 retv;                                   \
        retv = ctc_cmd_judge_is_num((STR));          \
        if (0 != retv)                                  \
        {                                             \
            ctc_cli_out("%% Incomplete command\n");  \
            return CLI_ERROR;                         \
        }                                             \
    }


#define CTC_CLI_GET_STR_UINT8(NAME, V, STR)         \
    {\
        uint16 i = 0;\
        uint16 j = 0;\
        char tmpstr[3] = "\0";\
        uint16 len = sal_strlen(STR);\
        for (i = 0; i <  len; i++)\
        {\
           if ((*(STR + i) <= '9' && *(STR + i) >= '0')\
               || (*(STR + i) <= 'f' && *(STR + i) >=  'a')\
               || (*(STR + i) <= 'F' && *(STR + i) >= 'A'))\
                {\
                }\
                else\
                {\
                     ctc_cli_out("%% Invalid %s value\n", NAME); \
                      return CLI_ERROR;                            \
                }\
        }\
        for (j = 0, i = 0; j < len; j += 2, i++)\
        {\
            if ((len % 2 == 1) && ((j + 1) == len))\
            {\
                sal_strncpy(tmpstr, STR + j, 1);\
                tmpstr[1] = '0';\
            }\
            else\
            {\
                sal_strncpy(tmpstr, STR + j, 2);\
            }\
            tmpstr[2] = '\0';\
            V[i] = sal_strtou32(tmpstr, NULL, 16);\
        }\
    }\


enum cmd_token_type_s
{
    cmd_token_paren_open,
    cmd_token_paren_close,
    cmd_token_cbrace_open,
    cmd_token_cbrace_close,
    cmd_token_brace_open,
    cmd_token_brace_close,
    cmd_token_separator,
    cmd_token_keyword,
    cmd_token_var,
    cmd_token_unknown
};
typedef enum cmd_token_type_s cmd_token_type;

#define CTC_VTY_CLIENT(vty)             (vty_client[vty->client_id])
#define source_quiet_on                 CTC_VTY_CLIENT(vty)->source_quiet_en
#define debug_for_on                    CTC_VTY_CLIENT(vty)->debug_for_en
#define g_string                        CTC_VTY_CLIENT(vty)->string
#define g_line                          CTC_VTY_CLIENT(vty)->line
#define g_cli_parser_param_en           CTC_VTY_CLIENT(vty)->cli_parser_param_en
#define g_ctc_vti                       CTC_VTY_CLIENT(vty)->ctc_vti
#define ctc_cli_out(fmt,...)            ctc_cli_out_ext(vty,fmt,##__VA_ARGS__)
#define ctc_cli_get_debug_desc(level)   ctc_cli_get_debug_desc_ext(vty,level)
#define MAX_NFA  1024
#define MAX_TAG  10
#define MAXMETA_CHR 128
#define META_CHRBIT 8
#define BIT_BLOCK MAXMETA_CHR/META_CHRBIT
#define CTC_CLI_MAX_LOCAL_CHIP_NUM      8
#define CTC_CLI_TIMESTAMP_MARKER_NUM    2

struct ctc_cli_app_ite_s
{
    char* username[8];
    uint8 slave_ip_list[8];
    uint8 slave_port_index_list[8];
    uint8 is_force[8];
};
typedef struct ctc_cli_app_ite_s ctc_cli_app_ite_t;  

struct ctc_vty_info_s
{
    ctc_cmd_node_t exec_node;
    ctc_cmd_node_t sdk_node;
    ctc_cmd_node_t cmodel_node;
    ctc_cmd_node_t oam_chan_node;
    ctc_cmd_node_t debug_node;
    ctc_cmd_node_t internal_node;
    ctc_cmd_node_t app_node;
    ctc_cmd_node_t dkits_node;
    ctc_cmd_node_t stress_node;
    ctc_cmd_node_t ptp_node;
    ctc_cmd_node_t asw_node;
    
    uint8 cli_parser_param_en;
    uint8 debug_for_en;
    uint8 api_ldev;
    uint8 api_lchip;
    /*only for multi-pp chip*/
    uint8 pp_id;
    /*0:pp_bmp mode, 1:pp_id mode*/
    uint8 pp_mode;
    uint8 master_ip;
    uint8 mep_type;
    uint8 nh_fp_field_cnt;
    uint16 linkagg_tid;
    uint8 qos_queue_cnt;
    uint8 nh_srh_num;
    uint8 stacking_tid;
    uint8 stats_is_new;
    uint16 linkagg_mem_num;
    uint16 port_mem_num;
    uint16 stacking_mem_num;
    uint32 ctc_cli_ol_vni_nhid;
    uint32 perf_io_entry_num;
    uint32 perf_ipv4_entry_num;
    uint32 perf_ipv6_entry_num;
    uint32 stacking_mem_port[255];   /*CTC_CLI_STACKING_REPLACE_MEMBER_MAX*/
    uint32 sdb_marker[CTC_CLI_TIMESTAMP_MARKER_NUM];
    uint32 mcast_mem_num;
    int  grep_cn;
    uint32 msg_pid;
    int32 ctc_sta;
    char* ctc_bol;  /*pointer*/
    int32 ctc_tag_stack[MAX_TAG];
    bool source_quiet_en;
    char ctc_nfa[MAX_NFA];
    char ctc_bit_tab[BIT_BLOCK];
    char print_buf[1024];
    char ctc_cli_out_print_buf[1026];
    char print_line[1024];
    char ctc_vti_read_buf[CTC_VTI_READ_BUFSIZ];
    char vti_out_buf[CTC_VTI_READ_BUFSIZ];
    char ctc_vti_out_buf[1024];
    char string[MAX_CLI_STRING_LEN];
    char line[MAX_CLI_STRING_LEN];
    char* ctc_cmd_execute_command_argv[CMD_ARGC_MAX];   /*pointer*/
    char *ctc_bop[MAX_TAG]; /*pointer*/
    char *ctc_eop[MAX_TAG]; /*pointer*/
    char sort_string[MAX_CLI_STRING_LEN];
    char grep_string[MAX_CLI_STRING_LEN];
    char debug_level_desc[64];
    char pkt_file_name[256];
    sal_file_t debug_fprintf_log_file;
    ctc_vti_t* ctc_vti; /*pointer*/
    ctc_cmd_desc_t** matched_desc_ptr;

    double npm_tx_rate[32];
    uint8  npm_ipg[32];
    uint8  pkt_buf_temp[9680];   /*CTC_PKT_MTU*/
    ctc_cli_app_ite_t ctc_app_ite;
    ipv6_addr_t nh_sid_list[3];    /*CTC_NH_SID_MAX_NUM*/
    ctc_l2_write_info_para_t l2_write_entry_para;
    void* ipmc_grp_info;
    void* ipmc_rpf_profile;
    void* npm_cache;
    void* oam_lmep; /*pointer*/
    void* qos_drop_array;
    void* nh_fp_field;
    void* nh_xlate;
    void* linkagg_mem_port;
    void* qos_queue;
    void* oam_bfd_interval;
    void* pkt_tx;
    void* port_phy_mapping_rst;
    void* acl_entry;
    void* scl_entry;
    void* flexq_profile;
    uint32 flexq_profile_num;
    void* stats_prop;
    void* stress_flow;
    void* stress_interface;
    void* stress_l2;
    void* stress_l3;
    void* stress_misc;
    void* stress_nexthop;
    void* stress_oam;
    void* mcast_mem_array;
    uint32* perf_io_data;
    uint32* perf_ipv4_data;
    uint32* perf_ipv6_data;
    sal_timer_t* perf_ptimer;   /*pointer*/
    void* chip_monitor_master[CTC_CLI_MAX_LOCAL_CHIP_NUM];  /*pointer*/
    ctc_cmd_node_t* cnodes[CTC_CLI_MODE_MAX];
    void* p_led_mapping_rst;
    uint8 led_mapping_loop;
};
typedef struct ctc_vty_info_s ctc_vty_info_t;

#define CTC_VTY_CLIENT_NUM  8
extern ctc_vty_info_t g_vty_client;
extern ctc_vty_info_t* vty_client[CTC_VTY_CLIENT_NUM];

/* APIs, user shall also call  CTC_CLI(), install_element() */

extern int
ctc_vti_read(int8* buf, uint32 buf_size,uint32 mode);
extern int
ctc_vti_read_cmd(ctc_vti_t* vty, const int8* szbuf, const uint32 buf_len);
extern void
ctc_vti_init_client(ctc_vty_info_t* p_vty_client);
extern void
ctc_vty_release_client(ctc_vti_t * vty);
extern void
ctc_vti_force_client_master(ctc_vti_t* vty);
extern void
ctc_cmd_init(int terminal);
extern void ctc_cli_register_print_fun(CTC_CLI_OUT_FUNC func);
extern unsigned char
ctc_cli_get_prefix_item(char** argv, unsigned char argc, char* prefix, unsigned char prefix_len);
extern int
ctc_vti_command(ctc_vti_t* vti, char* buf);

extern void
set_terminal_raw_mode(uint32 mode);

extern void
restore_terminal_mode(uint32 mode);

extern void
ctc_cli_enable_cmd_debug(int enable);

extern void
ctc_cli_enable_arg_debug(int enable);

extern uint32
ctc_cli_get_array_num(char* str);
extern int32
ctc_cmd_get_value_array(char* name, char* str, void* arr, uint32* arr_num, uint8 type);

#ifdef __cplusplus
}
#endif

#endif /* _CTC_CLI_H */

